 #include    "unp.h"                                                                                               
  2 #include    <time.h>
  3
  4 int
  5 main(int argc, char **argv)
  6 {
  7     int                 listenfd, connfd;
  8     struct sockaddr_in  servaddr;
  9     char                buff[MAXLINE];
 10     time_t              ticks;
 11
 12     listenfd = Socket(AF_INET, SOCK_STREAM, 0);
 13
 14     bzero(&servaddr, sizeof(servaddr));
 15     servaddr.sin_family      = AF_INET;
 16     servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
 17     servaddr.sin_port        = htons(13);   /* daytime server */
 18     Bind(listenfd, (SA *) &servaddr, sizeof(servaddr));
 19
 20     Listen(listenfd, LISTENQ);
 21
 22     for ( ; ; ) {
 23         connfd = Accept(listenfd, (SA *) NULL, NULL);
 24         ticks = time(NULL);
 25         snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
 26         Write(connfd, buff, strlen(buff));
 27         Close(connfd);
 28     }
 29 }
